home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / File::Copy.z / File::Copy
Encoding:
Text File  |  1998-10-30  |  8.2 KB  |  199 lines

  1.  
  2.  
  3.  
  4. FFFFiiiilllleeee::::::::CCCCooooppppyyyy((((3333))))                                                    FFFFiiiilllleeee::::::::CCCCooooppppyyyy((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      File::Copy - Copy files or filehandles
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.              use File::Copy;
  13.  
  14.              copy("file1","file2");
  15.              copy("Copy.pm",\*STDOUT);'
  16.              move("/dev1/fileA","/dev2/fileB");
  17.  
  18.              use POSIX;
  19.              use File::Copy cp;
  20.  
  21.              $n=FileHandle->new("/dev/null","r");
  22.              cp($n,"x");'
  23.  
  24.  
  25. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  26.      The File::Copy module provides two basic functions, copy and move, which
  27.      are useful for getting the contents of a file from one place to another.
  28.  
  29.      +o   The copy function takes two parameters: a file to copy from and a
  30.          file to copy to. Either argument may be a string, a FileHandle
  31.          reference or a FileHandle glob. Obviously, if the first argument is a
  32.          filehandle of some sort, it will be read from, and if it is a file
  33.          _n_a_m_e it will be opened for reading. Likewise, the second argument
  34.          will be written to (and created if need be).
  35.  
  36.          NNNNooootttteeee tttthhhhaaaatttt ppppaaaassssssssiiiinnnngggg iiiinnnn ffffiiiilllleeeessss aaaassss hhhhaaaannnnddddlllleeeessss iiiinnnnsssstttteeeeaaaadddd ooooffff nnnnaaaammmmeeeessss mmmmaaaayyyy lllleeeeaaaadddd ttttoooo
  37.          lllloooossssssss ooooffff iiiinnnnffffoooorrrrmmmmaaaattttiiiioooonnnn oooonnnn ssssoooommmmeeee ooooppppeeeerrrraaaattttiiiinnnngggg ssssyyyysssstttteeeemmmmssss;;;; iiiitttt iiiissss rrrreeeeccccoooommmmmmmmeeeennnnddddeeeedddd tttthhhhaaaatttt
  38.          yyyyoooouuuu uuuusssseeee ffffiiiilllleeee nnnnaaaammmmeeeessss wwwwhhhheeeennnneeeevvvveeeerrrr ppppoooossssssssiiiibbbblllleeee....  Files are opened in binary
  39.          mode where applicable.  To get a consistent behavour when copying
  40.          from a filehandle to a file, use binmode on the filehandle.
  41.  
  42.          An optional third parameter can be used to specify the buffer size
  43.          used for copying. This is the number of bytes from the first file,
  44.          that wil be held in memory at any given time, before being written to
  45.          the second file. The default buffer size depends upon the file, but
  46.          will generally be the whole file (up to 2Mb), or 1k for filehandles
  47.          that do not reference files (eg. sockets).
  48.  
  49.          You may use the syntax use File::Copy "cp" to get at the "cp" alias
  50.          for this function. The syntax is _e_x_a_c_t_l_y the same.
  51.  
  52.      +o   The move function also takes two parameters: the current name and the
  53.          intended name of the file to be moved.  If the destination already
  54.          exists and is a directory, and the source is not a directory, then
  55.          the source file will be renamed into the directory specified by the
  56.          destination.
  57.  
  58.          If possible, _m_o_v_e() will simply rename the file.  Otherwise, it
  59.          copies the file to the new location and deletes the original.  If an
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FFFFiiiilllleeee::::::::CCCCooooppppyyyy((((3333))))                                                    FFFFiiiilllleeee::::::::CCCCooooppppyyyy((((3333))))
  71.  
  72.  
  73.  
  74.          error occurs during this copy-and-delete process, you may be left
  75.          with a (possibly partial) copy of the file under the destination
  76.          name.
  77.  
  78.          You may use the "mv" alias for this function in the same way that you
  79.          may use the "cp" alias for copy.
  80.  
  81.      File::Copy also provides the syscopy routine, which copies the file
  82.      specified in the first parameter to the file specified in the second
  83.      parameter, preserving OS-specific attributes and file structure.  For
  84.      Unix systems, this is equivalent to the simple copy routine.  For VMS
  85.      systems, this calls the rmscopy routine (see below).  For OS/2 systems,
  86.      this calls the syscopy XSUB directly.
  87.  
  88.      SSSSppppeeeecccciiiiaaaallll bbbbeeeehhhhaaaavvvviiiioooorrrr iiiiffff ssssyyyyssssccccooooppppyyyy is defined (VMS and OS/2)
  89.  
  90.      If both arguments to copy are not file handles, then copy will perform a
  91.      "system copy" of the input file to a new output file, in order to
  92.      preserve file attributes, indexed file structure, _e_t_c.  The buffer size
  93.      parameter is ignored.  If either argument to copy is a handle to an
  94.      opened file, then data is copied using Perl operators, and no effort is
  95.      made to preserve file attributes or record structure.
  96.  
  97.      The system copy routine may also be called directly under VMS and OS/2 as
  98.      File::Copy::syscopy (or under VMS as File::Copy::rmscopy, which is the
  99.      routine that does the actual work for syscopy).
  100.  
  101.      rmscopy($from,$to[,$date_flag])
  102.          The first and second arguments may be strings, typeglobs, typeglob
  103.          references, or objects inheriting from IO::Handle; they are used in
  104.          all cases to obtain the _f_i_l_e_s_p_e_c of the input and output files,
  105.          respectively.  The name and type of the input file are used as
  106.          defaults for the output file, if necessary.
  107.  
  108.          A new version of the output file is always created, which inherits
  109.          the structure and RMS attributes of the input file, except for owner
  110.          and protections (and possibly timestamps; see below).  All data from
  111.          the input file is copied to the output file; if either of the first
  112.          two parameters to rmscopy is a file handle, its position is
  113.          unchanged.  (Note that this means a file handle pointing to the
  114.          output file will be associated with an old version of that file after
  115.          rmscopy returns, not the newly created version.)
  116.  
  117.          The third parameter is an integer flag, which tells rmscopy how to
  118.          handle timestamps.  If it is < 0, none of the input file's timestamps
  119.          are propagated to the output file.  If it is > 0, then it is
  120.          interpreted as a bitmask: if bit 0 (the LSB) is set, then timestamps
  121.          other than the revision date are propagated; if bit 1 is set, the
  122.          revision date is propagated.  If the third parameter to rmscopy is 0,
  123.          then it behaves much like the DCL COPY command:  if the name or type
  124.          of the output file was explicitly specified, then no timestamps are
  125.          propagated, but if they were taken implicitly from the input
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. FFFFiiiilllleeee::::::::CCCCooooppppyyyy((((3333))))                                                    FFFFiiiilllleeee::::::::CCCCooooppppyyyy((((3333))))
  137.  
  138.  
  139.  
  140.          filespec, then all timestamps other than the revision date are
  141.          propagated.  If this parameter is not supplied, it defaults to 0.
  142.  
  143.          Like copy, rmscopy returns 1 on success.  If an error occurs, it sets
  144.          $!, deletes the output file, and returns 0.
  145.  
  146. RRRREEEETTTTUUUURRRRNNNN
  147.      All functions return 1 on success, 0 on failure.  $! will be set if an
  148.      error was encountered.
  149.  
  150. AAAAUUUUTTTTHHHHOOOORRRR
  151.      File::Copy was written by Aaron Sherman <_a_j_s@_a_j_s._c_o_m> in 1995, and
  152.      updated by Charles Bailey <_b_a_i_l_e_y@_g_e_n_e_t_i_c_s._u_p_e_n_n._e_d_u> in 1996.
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.